package edu.hubu.book.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Map;

/**
 * @author waxijiang
 */
public class JsonUtils {
    public static <K, V> String mapToJson(Map<K, V> map) {
        // 转换为Json对象
        ObjectMapper mapper = new ObjectMapper();
        String resultStr;
        try {
            resultStr = mapper.writeValueAsString(map);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
        return resultStr;
    }
}
